package com.fred.taobao.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.fred.taobao.domain.DeliveryDomain;
import com.fred.taobao.util.SqlUtil;

public class DeliverDao {
	public List<DeliveryDomain> getDeliveriesFromSql(String startDate,String endDate){
		SqlUtil sqlUtil=new SqlUtil();
		Connection conn=sqlUtil.getConnection();
		PreparedStatement pre=null;
		ResultSet result=null;
		List<DeliveryDomain> deliveries=new ArrayList<DeliveryDomain>();
		try{
			pre=conn.prepareStatement("select * from sell_table sell ,item_table item where sell.item_iid=item.num_iid and sell.delivery_status='WAIT_SELLER_SEND_GOODS' and sell.order_date>=? and sell.order_date<=?");
			pre.setString(1, startDate);
			pre.setString(2, endDate);
			result=pre.executeQuery();
			while(result.next()){
				DeliveryDomain delivery = new DeliveryDomain();
				delivery.setNumIid(result.getString("item_iid"));
				delivery.setNum(String.valueOf(result.getInt("order_number")));
				delivery.setTid(result.getString("order_id"));
				delivery.setTitle(result.getString("name"));
				deliveries.add(delivery);
			}
			return deliveries;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
}
